package com.rb;

import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * Created by walker on 17-7-11.
 *
 */
public enum  FieldMapping
{
    INT("int",Integer.class, "int"), STRING("varchar",String.class,null), DATETIME("datetime", Timestamp.class,null),
    LONG("bigint", Long.class,"long"),FLOAT("float", Float.class,"float"),DECIMAL("decimal", BigDecimal.class,null),BOOLEAN("tinyint", Boolean.class,"boolean");//double float...没有的再加
    FieldMapping(String dbFieldType, Class classType, String notNullType){
        this.dbFieldType = dbFieldType;
        this.classType = classType;
        this.notNullType = notNullType!=null?notNullType:classType.getSimpleName();
    }

    private String dbFieldType;
    private Class classType;
    private String notNullType;

    public static FieldMapping getByDbFieldType(String dbFieldType){
        FieldMapping[] arr = FieldMapping.values();
        for(FieldMapping item : arr){
            if(StringUtils.equalsIgnoreCase(dbFieldType, item.getDbFieldType())){
                return item;
            }
        }
        return null;
    }

    public String getDbFieldType()
    {
        return dbFieldType;
    }

    public void setDbFieldType(String dbFieldType)
    {
        this.dbFieldType = dbFieldType;
    }

    public Class getClassType()
    {
        return classType;
    }

    public void setClassType(Class classType)
    {
        this.classType = classType;
    }

    public String getNotNullType()
    {
        return notNullType;
    }

    public void setNotNullType(String notNullType)
    {
        this.notNullType = notNullType;
    }

}
